<template class="c1">
  <div>
    <div class="header">
      <div class="warp">
        <ul class="header-left">
          <li class="logo"><a href="">WeShoppnig</a></li>
        </ul>
        <ul class="header-right">
          <li class="cart">
            <a href="">
              <i class="el-icon-goods" style="margin-top: -10px"></i>
            </a>
            <div class="cart-list">
              购物车商品数量
            </div>
          </li>
        </ul>
      </div>
    </div>
    <div class="nav">
      <div class="warp">
        <div class="logo1">
        </div>
        <div class="nav-bar"></div>
        <div class="search">
          <el-form>
            <input v-model="name" placeholder="模糊查询" type="text">
            </input>
            <button class="el-icon-search" @click="getGoodList"></button>
            <div class="hot-list">
              <ul>
                <li v-for="item in nameArr" class="bend">{{ item }}</li>
              </ul>
            </div>
          </el-form>
        </div>
      </div>
    </div>
    <div class="banner">
      <div class="warp">
        <div class="banner-box">
          <template>
            <el-carousel :interval="4000" arrow="none" height="460px" indicator-position="none">
              <el-carousel-item v-for="(item,index) in businessArr" :key="index">
                <el-image :src="item.businessPic" class="image"
                >
                </el-image>
              </el-carousel-item>
            </el-carousel>
          </template>
          <div class="slide">
            <ul>
              <li v-for="(item, index) in categoryList" class="li-text" @mouseenter="getGoodsByCatId(index+1)">
                {{ item.categoryName }}
                <i class="el-icon-arrow-right"></i>
                <div class="slide-list">
                  <ul>
                    <li v-for="item in goodList1">
                      <el-image :src="item.goodsPic" class="liImg"
                      >
                      </el-image>
                      <div class="liDesc" @click="getGoodInfo(item.goodsId)">{{ item.goodsName }}</div>
                    </li>
                  </ul>
                  <ul>
                    <li v-for="item in goodList2">
                      <el-image :src="item.goodsPic" class="liImg"
                      >
                      </el-image>
                      <div class="liDesc" @click="getGoodInfo(item.goodsId)">{{ item.goodsName }}</div>
                    </li>
                  </ul>
                  <ul>
                    <li v-for="item in goodList3">
                      <el-image :src="item.goodsPic" class="liImg"
                      >
                      </el-image>
                      <div class="liDesc" @click="getGoodInfo(item.goodsId)">{{ item.goodsName }}</div>
                    </li>
                  </ul>
                  <ul>
                    <li v-for="item in goodList4">
                      <el-image :src="item.goodsPic" class="liImg"
                      >
                      </el-image>
                      <div class="liDesc" @click="getGoodInfo(item.goodsId)">{{ item.goodsName }}</div>
                    </li>
                  </ul>
                </div>
              </li>
            </ul>
          </div>
        </div>
      </div>
    </div>
    <el-dialog :before-close="handleClose" :visible.sync="dialogTableVisible" title="详情信息" width="70%">
      <div class="dialog-div">
        <div class="div-left">
          <el-image :src="picSrc" class="left-img"></el-image>
        </div>
        <div class="div-right-top">
          <h2>{{ good.goodsName }}</h2>
          <h3>{{ good.goodsDescription }}</h3>
          <div class="business-info">
            <div class="h3-1">
              <el-collapse>
                <el-collapse-item :title="business.businessName" name="1">
                  <div>{{
                      business.businessAddress
                    }}
                  </div>
                  <div class="business-img">
                    <el-image :src="business.businessPic" class="el-image-1"></el-image>
                  </div>
                  <div class="right-1">
                    <div class="right-2" style="border-bottom: 1px solid #b0b0b0"> 电话：{{ business.businessTel }}</div>
                    <div class="right-2" style="border-bottom: 1px solid #b0b0b0"> 地址 ：{{
                        business.businessAddress
                      }}
                    </div>
                    <div class="right-2"> 地址 ：{{ business.businessAddress }}</div>
                  </div>
                </el-collapse-item>
              </el-collapse>
            </div>
          </div>
          <h2>商品评价</h2>
          <div class="div-right-center">
            <el-carousel :autoplay="true" direction="vertical" height="200px">
              <el-carousel-item v-for="(item,index) in evaluations" :key="index">
                <h3 id="medium-1" class="medium">{{ item.evaluation }}</h3>
              </el-carousel-item>
            </el-carousel>
          </div>
          <div class="div-right-foot">
            <el-buton class="el-icon-goods" @click="addCart()">
              加入购物车！
            </el-buton>
          </div>

        </div>

      </div>
    </el-dialog>
  </div>

</template>
<script>
export default {
  created() {
    this.listBusiness();
    this.listCategory();
    this.getUserId();
  }, data() {
    return {
      businessArr: [],
      categoryList: [],
      goodList: [],
      goodList1: [],
      goodList2: [],
      goodList3: [],
      goodList4: [],
      nameArr: [],
      dialogTableVisible: false,
      name: '',
      good: {},
      picSrc: '',
      business: {
        businessName: '',
        businessPic: ''
      },
      evaluations: [],
      goodId: 0,
      cart: {
        cartId: 0,
        userId: 0,
        goodId: '',
        goodNum: 0,
      }
    }
  }, methods: {
    listBusiness() {
      this.$http.get('business/business/getList', {
        // 解构赋值
      }).then(({data: res}) => {
        this.businessArr = res.data
      }).catch(() => {

      })
    },
    listCategory() {
      this.$http.get('goodsCategory/goodscategory/listAll', {}).then(({data: res}) => {
        this.categoryList = res.data
      }).catch(() => {
      })
    },
    getGoodsByCatId(index) {
      this.$http.get('goobs/goods/getGoodsByCatId', {params: {id: index}}).then(({data: res}) => {
        let list = res.data
        this.goodList1 = list.slice(0, 4)
        this.goodList2 = list.slice(5, 8)
        this.goodList3 = list.slice(9, 13)
        this.goodList4 = list.slice(14, 18)
      }).catch(() => {
      })
    },
    getGoodInfo(index) {
      this.dialogTableVisible = true
      this.goodId = index
      this.$http.get('goobs/goods/getParamById', {params: {id: index}}).then(({data: res}) => {
        this.good = res.data
        this.picSrc = res.data.goodsPic
        this.business = res.data.businessEntity
        this.evaluations = res.data.evaluationEntities
      }).catch(() => {
      })

    },
    getGoodList() {

      if (this.name == '') {
        this.$message("未输入关键字");
      } else {
        this.nameArr.push(this.name)
        this.$http.get('goobs/goods/getGoodsLikeName', {
          params: {name: this.name}
          // 解构赋值
        }).then(({data: res}) => {
          this.goodsList = res.data;
          this.name = ''
        }).catch(() => {

        })
      }

    },
    addCart() {
      this.getUserId()
      this.cart.goodId = this.goodId;
      this.cart.goodNum = 1
      this.$http.post('/cart/cart/createCart', {
        cartId: this.cart.cartId,
        goodId: this.cart.goodId,
        goodNum: this.cart.goodNum,
        userId: this.cart.userId
      }).then(({data: res}) => {
        console.log(res.data)
      }).catch(() => {

      })
      this.$message('添加成功！');
    },
    handleClose(done) {
      done();
      this.business = {};
      this.picSrc = ''
    }
    , getUserId() {
      this.$http.get('/cart/cart/getId', {
        // 解构赋值
      }).then(({data: res}) => {
        this.cart.userId = res
      }).catch(() => {

      })
    }
  }
}
</script>
<style>
.header {
  width: 100%;
  height: 40px;
  background-color: #333;
  min-width: 1200px;

}

.warp {
  width: 80%;
  margin: 0 auto;
  height: 40px;

}

.header-left {
  float: left;
  height: 12px;
}

.header-right {
  float: right;
  height: 12px;
}

.header li {
  float: left;
  list-style: none;
}

.header a {
  font-size: 12px;
  color: white;
}

.header span {
  color: #424242;
  margin: 0 3.6px;
  font-size: 12px;
}

.cart {
  position: relative;
  width: 120px;
  height: 40px;
  text-align: center;
  line-height: 40px;
  background-color: #424242;
  margin-left: 25px;
  margin-top: -14px;
}

.logo {
  margin-right: 10px;
}

.cart:hover {
  background-color: #FFF;

}

.cart:hover a {
  color: #ff6700;
}

.cart-list {
  position: absolute;
  right: 0;
  top: 40px;
  width: 290px;
  /*隐藏元素的高速设置为0*/
  height: 0;
  line-height: 100px;
  background-color: #FFF;
  box-shadow: 0 2px 2px rgb(0, 0, 0, .15);
  color: #424242;
  text-align: center;
  transition: all .3s;
  /*高度为0，隐藏文字*/
  overflow: hidden;
  z-index: 4;
}

.cart:hover > .cart-list {
  height: 100px;
}

/*----------------------------------------------------------------------------------------------*/
.nav {
  clear: both;
  width: 100%;
  height: 100px;
  background-color: #fff;
}

.nav-bar {
  float: left;
  width: 658.36px;
  height: 100px;
}

.logo1 {
  float: left;
  width: 234px;
  height: 100px;
  background: url("~@/assets/img/img.png") no-repeat center center;
}

.search {
  position: relative;
  float: right;
  width: 296px;
  height: 50px;
  margin-top: 25px;
}

.search input {
  margin-left: 20px;
  width: 225px;
  height: 50px;
  padding: 0 30px;
  border: 1px solid #e0e0e0;
  border-right: none;
}

.search button {
  float: right;
  height: 50px;
  width: 50px;
  background-color: #fff;
  border: 1px solid #e0e0e0;
  transition: all .1s;
}

.search button:hover {
  background-color: #ff6700;
  border-color: #ff6700;
  color: #fff;
  display: block;
}

.search input:hover, .search input:hover + button {
  border-color: #b0b0b0;
}

.hot-list {
  position: absolute;
  width: 227px;
  height: 0;
  line-height: 0;
  background-color: #fff;
  border: 1px solid #b0b0b0;
  border-top: none;
  transition: all .3s;
  /*高度为0，隐藏文字*/
  overflow: hidden;
  margin-left: 20px;
  z-index: 3;

}

.hot-list li {
  border: #fff solid 2px;
  list-style: none;
  width: 225px;
  height: 30px;
  top: 0;
  left: 20px;
  line-height: 30px;
  text-indent: 20px;
  margin-left: -40px;

}

.bend:hover {
  background-color: #8a979e;
}

.search input:focus ~ .hot-list {
  line-height: 200px;
  height: 200px;
}

/*------------------------------------------------------------------------------------------------*/
.banner {
  width: 100%;
  height: 460px;
  background-color: #fff;
}

.image {
  width: 100%;
  height: 100%;

}

.banner-box {
  position: relative;
  width: 100%;
  height: 460px;
  background-color: #409EFF;
  z-index: 1;

}

.slide {
  position: absolute;
  top: 0;
  left: 0;
  width: 234px;
  height: 460px;
  padding: 20px 0;
  background-color: #8a979e;
  z-index: 2;
}

.slide i {
  float: right;
  margin-right: 30px;
  color: #e0e0e0;
  margin-top: 15px;
}

.li-text {
  color: #e0e0e0;
  list-style: none;
  height: 42px;
  width: 234px;
  line-height: 42px;
  padding-left: 30px;
  text-align: left;
  margin-left: -40px;
}

.li-text:hover {
  background-color: #ff6700;
}

.slide-list {
  position: absolute;
  width: 0;
  height: 460px;
  overflow: hidden;
  background-color: #fff;
  border-left: none;
  opacity: 0.9;
  box-shadow: 0 8px 16px rgba(0, 0, 0, .18);
  transition: all .3s;
  top: 0;
  left: 234px;
}

.slide li:hover > .slide-list {
  width: 900px;

}

.slide-list > ul {
  width: 191px;
  float: left;
}

.slide-list li {
  width: 190px;
  height: 115px;
  list-style: none;
}

.liImg {
  float: left;
  width: 40px;
  margin-top: 30px;
  background-size: 100%;
}

.liDesc {
  float: left;
  width: 140px;
  margin-top: 30px;
  display: inline-block;
  text-indent: 20px;
  font-size: 14px;
  color: #333;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/*----------------------------------------------------------------------*/
.dialog-div {
  width: 100%;
  height: 600px;
  position: relative;
}


.div-left {
  position: absolute;
  float: left;
  width: 250px;
  height: 250px;
  top: 175px;
  left: 120px;
  border-right: 1px gray solid;
}

.div-right-top {
  float: right;
  width: 50%;
  height: 200px;
  /*background-color: #00ff00;*/
}

.left-img {
  width: 100%;
  height: 100%;
  opacity: 0.9;
}

h2 {
  text-indent: 30px;
  color: black;
}

h3 {
  margin: auto;
  text-indent: 30px;
  margin-top: 10px;
  height: 20px;
}

.h3-1 {
  margin-top: 10px;
  text-indent: 30px;
  color: black;
}

.business-img {
  float: left;
  margin-left: 30px;
  width: 150px;
  height: 100px;
  background-size: 100%;
}

.el-image-1 {
  width: 100%;
  height: 100%;
  margin-left: -60px;
  float: left;
}

.right-1 {
  float: left;
  width: 410px;
  margin-left: -30px;
}

.right-2 {
  height: 30px;
  line-height: 30px;
}

.div-right-center {
  width: 90%;
  height: 200px;
  margin-left: 30px;
}

.el-carousel__item h3 {
  /*color: #475669;*/
  font-size: 14px;
  opacity: 0.75;
  line-height: 200px;
  margin: 0;
}

.el-carousel__item:nth-child(2n) {
  background-color: #99a9bf;

}

.el-carousel__item:nth-child(2n+1) {
  background-color: #d3dce6;

}

#medium-1 {
  text-align: center;
}

.el-icon-goods {
  width: 100%;
  height: 60px;
  text-align: center;
  line-height: 60px;
  font-size: 22px;
}
</style>